package MyFile;


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLOutput;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true){
            String input = sc.nextLine();
            if (input.equals("1")){
                System.out.println(readFile("testfile.txt"));
            }else if (input.equals("Q")){
                System.out.println("Quit");
                break;
            }else{
                System.out.println("Wrong input, Please re-choose");
                System.out.println("Menu Function Test");
                System.out.println("1: Count Lines");
                System.out.println("Q: Quit");
            }
        }

    }

    public static int readFile(String fileName) {
        FileReader fr = null;
        BufferedReader br = null;

        int count = 0;

        try {
            fr = new FileReader(fileName);
            br = new BufferedReader(fr);

            String value = br.readLine();
            while (value != null)
            {
                if (!"".equals(value))
                {
                    count++;
                }
                value = br.readLine();
            }
        }
        catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                if (br != null)
                    br.close();
                if (fr != null)
                    fr.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
        return count;
    }
}
